<!DOCTYPE html>
<html>

<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>图像识别APP管理系统</title>
	<link href="css/common.css" rel="stylesheet">
	<link rel="stylesheet" href="css/layui.css" media="all">
	<link rel="icon" href="image/favicon.ico" sizes="32x32">
	<link id="layuicss-layer" rel="stylesheet" href="css/modules/layer/default/layer.css" media="all">
	<script src="js/jquery-1.12.4.js"></script>
	<script type="text/javascript" src="js/layui.js" charset="utf-8"></script>
	<script type="text/javascript" src="js/common.js" charset="utf-8"></script>
	<script type="text/javascript">
		var user = '';
		//登陆
		function login() {
			layui.use(["layer", "element"], function () {
				var layer = layui.layer;
				var element = layui.element;
				var username = $("#username").val();
				var password = $("#password").val();
				username = $.trim(username);
				password = $.trim(password);
				if (username == "") {
					layer.msg("用户名不能为空");
					return;
				}
				if (password == "") {
					layer.msg("密码不能为空");
					return;
				}
				var data = {
					"username": username,
					"password": password
				}
				$("#password").blur();
				$("#loginbtn").blur();
				loginLoad = layer.load(2, { shade: 0.1 })
				user = username;
				console.log(data);
				sendPostAjax(
					webUrl + "/userinfo/login",
					data,
					loginCallBack
				);
			})
		}

		function loginCallBack(data) {
			layer.close(loginLoad);
			if (data == null) {
				return;
			}
			if (data.errCode == "000000") {
				layer.msg(data.errMsg);
				if(data.data.userType < 1) {
					layer.msg("没有权限，请联系管理员授权！");
					return;
				}
			} else {
				layer.alert(data.errMsg);
				user = '';
				return;
			}
			console.log(data);
			setCookie("userName", user);
			setCookie("token", data.data.token);
			setCookie("name", data.data.nickname);
			setCookie("roleName", data.data.authorities[0].authority);

			window.location.href = "main.html";
		}

		$(function () {
			$("#password").keydown(function (e) {
				if (e.keyCode == 13) {
					login();
				}
			})
		})		
	</script>
</head>

<body class="loginbg">
	<div class="mainbox">
		<h1>图像识别APP管理系统</h1>
		<div class="registerBox">
			<h2>系统用户登录</h2>
			<div class="inputBar registerItem"><label>账号：</label><input autocomplete="off" type="text" id="username"
					placeholder="请输入账号" /></div>
			<div class="inputBar registerItem"><label>密码：</label><input type="password" id="password" placeholder="请输入密码" />
			</div>
			<div class="registerBtn" id="registerBtn"><button id="loginbtn" onclick="login()">登陆</button></div>
		</div>
		<div class="copyright">©2022 信息科学技术学院 软件技术部</div>
	</div>

</body>

</html>